﻿using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;

namespace Red.Controls
{
    public partial class ResizeGrip : UserControl
    {
        #region Public Properties

        public bool IsHorizontalResizeEnabled { get; set; }
        public bool IsVerticalResizeEnabled { get; set; }

        #endregion Public Properties

        #region C-Tor

        public ResizeGrip()
        {
            InitializeComponent();
        }

        #endregion C-Tor

        #region Event Handlers

        private void Thumb_DragDelta( object sender, DragDeltaEventArgs e )
        {
            Resize?.Invoke( e.HorizontalChange, e.VerticalChange );
        }

        private void Thumb_MouseEnter( object sender, MouseEventArgs e )
        {
            if( IsHorizontalResizeEnabled && IsVerticalResizeEnabled)
            {
                Mouse.OverrideCursor = Cursors.SizeNWSE;
            }
            else if( IsVerticalResizeEnabled )
            {
                Mouse.OverrideCursor = Cursors.SizeNS;
            }
            else if( IsHorizontalResizeEnabled)
            {
                Mouse.OverrideCursor = Cursors.SizeWE;
            }
            else
            {
                Mouse.OverrideCursor = Cursors.No;
            }
        }

        private void Thumb_MouseLeave( object sender, MouseEventArgs e )
        {
            Mouse.OverrideCursor = null;
        }

        #endregion Event Handlers

        #region Events

        public delegate void ResizeHandler( double xDelta, double yDelta );
        public event ResizeHandler Resize;

        #endregion Events
    }
}
